/*
 * Copyright 2008 Federal Emergency Management Agency
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 *    
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 *  
 */
package gov.fema.hazus.bdc.client.hazards.wind;

import gov.fema.hazus.bdc.client.common.ui.AbstractWidget;
import gov.fema.hazus.bdc.client.common.ui.InCASTTabPanel;
import gov.fema.hazus.bdc.client.hazards.wind.buildingdesign.WindBuildingDesignForm;
import gov.fema.hazus.bdc.client.hazards.wind.hazard.WindHazardForm;
import gov.fema.hazus.bdc.client.hazards.wind.manufacturedhousing.ManufacturedHousingForm;
import gov.fema.hazus.bdc.client.hazards.wind.roof.WindRoofForm;
import gov.fema.hazus.bdc.client.hazards.wind.wallsopenings.WallsAndOpeningsForm;
import gov.fema.hazus.bdc.shared.entity.Building;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.TabPanel;

public class WindWidget extends AbstractWidget {

	private DockPanel docker;
	private InCASTTabPanel tabPanel;
	
	private WindHazardForm windHazardForm;
	private WindBuildingDesignForm windBuildingDesignForm;
	private WindRoofForm windRoofForm;
	private WallsAndOpeningsForm wallsAndOpeningsForm;
	private ManufacturedHousingForm manufacturedHousingForm;
	
	private Building building;
	
	public WindWidget(Building building)
	{
		
		this.building = building;
		
		docker = new DockPanel();
		
		// set up a tab panel
		tabPanel = new InCASTTabPanel();		
		// tabPanel.setWidth("100%");
		
		// set up forms
		windHazardForm = new WindHazardForm(building);
		windHazardForm.setStyleName("building-detail-form");
		windBuildingDesignForm = new WindBuildingDesignForm(building);
		windBuildingDesignForm.setStyleName("building-detail-form");
		windRoofForm = new WindRoofForm(building);
		windRoofForm.setStyleName("building-detail-form");
		manufacturedHousingForm = new ManufacturedHousingForm(building);
		manufacturedHousingForm.setStyleName("building-detail-form");
		wallsAndOpeningsForm = new WallsAndOpeningsForm(building);
		wallsAndOpeningsForm.setStyleName("building-detail-form");
		
		
		// add to panel
		tabPanel.add(windHazardForm, windHazardForm.getTabTitle());
		tabPanel.add(windBuildingDesignForm, windBuildingDesignForm.getTabTitle());
		tabPanel.add(windRoofForm, windRoofForm.getTabTitle() );
		tabPanel.add(wallsAndOpeningsForm, wallsAndOpeningsForm.getTabTitle());
		tabPanel.add(manufacturedHousingForm, manufacturedHousingForm.getTabTitle() );
		
		// default
		tabPanel.selectTab(0);
		
		// add tabs to docker
		docker.add(tabPanel, DockPanel.CENTER);
		
		// add a style to the sub tabs
		tabPanel.setStyleName("emcode-subnav-tabbar");

		initWidget(docker);		
	}

	public void updateBuilding(Building building) {
		
		windHazardForm.updateBuilding(building);
		windBuildingDesignForm.updateBuilding(building);
		windRoofForm.updateBuilding(building);
		manufacturedHousingForm.updateBuilding(building);
		wallsAndOpeningsForm.updateBuilding(building);
		
	}
}
